package com.benmei.weike.service;

import com.benmei.weike.dao.DiscountCouponDao;
import com.benmei.weike.dao.MembNewUserScholarshipDao;
import com.benmei.weike.entity.DiscountCoupon;
import com.benmei.weike.entity.MembNewUserScholarship;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DiscountCouponService {

    @Resource
    private DiscountCouponDao discountCouponDao;
    @Resource
    private MembNewUserScholarshipDao membNewUserScholarshipDao;

    Logger logger = LoggerFactory.getLogger(DiscountCouponService.class);

    public void InsertDiscountCoupon(Integer memb_id){

        MembNewUserScholarship ship = membNewUserScholarshipDao.findByMembId(memb_id);
        if (ship != null) {
            logger.warn("已领取红包，memb_id=" + memb_id);
            return;
        }

        // 1. 添加红包领取记录
        MembNewUserScholarship pojo = new MembNewUserScholarship(memb_id);
        membNewUserScholarshipDao.insert(pojo);

        // 2.添加到优惠券表中
        DiscountCoupon discountCoupon = new DiscountCoupon();
        discountCoupon.setCourse_type(1);
        discountCoupon.setMemb_id(memb_id);
        discountCoupon.setDeleted(0);
        discountCoupon.setOver((double) 0);
        discountCoupon.setSubtract((double) 108);
        discountCoupon.setDiscount_state(0);
        discountCouponDao.insertDiscountCoupon(discountCoupon);
    }

    public List<DiscountCoupon> getAllMyCoupon(Integer memb_id){
        List<DiscountCoupon> discountCouponList = new ArrayList<>();
        discountCouponList=discountCouponDao.searchDiscountCoupon(memb_id);
        return  discountCouponList;
    }
}
